import { Component, OnInit } from '@angular/core';
import {Router,ActivatedRoute} from "@angular/router";

@Component({
  selector: 'app-roster-training',
  templateUrl: './roster-training.component.html',
  styleUrls: ['./roster-training.component.css'],
})
export class RosterTrainingComponent implements OnInit {
  className:string;
  currentIndex:number;//当前路由索引
  classID:string;
  trainingID:string;
  constructor(
    private routerInfo:ActivatedRoute,
    private  route:Router,
  ) { }

  ngOnInit() {
    this.className = this.routerInfo.snapshot.params.className;
    this.classID = this.routerInfo.snapshot.params.classID;
    this.trainingID = this.routerInfo.snapshot.params.ID;
    this.matchingRouter();
  }
  goToStart(){
    this.route.navigate(['home/start']);
  }
  jumpTrainingMinute(){
    this.route.navigate(['home/roster',{ID:this.trainingID,className:this.className,classID:this.classID}]);
    this.currentIndex = 0;
  }
  jumpTrainingExexplain(){
    this.route.navigate(['explain'],{relativeTo:this.routerInfo});
    this.currentIndex=2;
  }
  jumpTrainingCode(){
    this.route.navigate(['code',{ID:this.trainingID}],{relativeTo:this.routerInfo});
    this.currentIndex =1;
  }
  //匹配路由
  matchingRouter(){
    if(/code/g.test(location.href)){
      this.currentIndex =1;
    }else if (/explain/g.test(location.href)){
      this.currentIndex = 2;
    }else {
    this.currentIndex = 0;
    }
  }
}
